/************************************/
/* CrearUsuarioXmlOpcionScreen.java */
/************************************/
/*
  Autor  : Edgar Gonzalez
  email  : egonzale@ucla.edu.ve
  Version: 1.0 en J2ME
  Fecha  : 04 de enero del 2010
*/
package ucla.dcyt.fomento.xml;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.UiApplication;

public class CrearUsuarioXmlOpcionScreen extends MainScreen implements FieldChangeListener {
	
	private String opciones[] = { "Crear", "Leer", "Actualizar", "Eliminar" };
	private ObjectChoiceField miObjectChoiceField;
    private ButtonField Salir;
    private ButtonField Enviar;
    private LabelField Etiqueta;
    private HorizontalFieldManager buttonManagerHorizontal;
	private VerticalFieldManager buttonManagerVertical;
	
	public CrearUsuarioXmlOpcionScreen() {
		buttonManagerHorizontal = new HorizontalFieldManager(Field.FIELD_LEFT);
        buttonManagerVertical = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL | Field.FIELD_LEFT);
        Etiqueta = new LabelField("::::Ejemplo de Kxml2::::",Field.FIELD_HCENTER);
        miObjectChoiceField = new ObjectChoiceField("Seleccione: ", opciones, 0, Field.FIELD_LEFT);
        buttonManagerVertical.add(Etiqueta);
		buttonManagerVertical.add(miObjectChoiceField);
		Enviar = new ButtonField("Enviar", ButtonField.CONSUME_CLICK);
        Enviar.setChangeListener(this);
        Salir = new ButtonField("Salir", ButtonField.CONSUME_CLICK);
        Salir.setChangeListener(this);
        buttonManagerHorizontal.add(Enviar);
        buttonManagerHorizontal.add(Salir);
        add(buttonManagerVertical);
        add(buttonManagerHorizontal);
	}
	
	public void fieldChanged(Field field, int context) {
		if (field == Salir) {
			System.exit(0);
	    }
		if (field == Enviar) {
			if (miObjectChoiceField.getSelectedIndex()==0)
			{
			 UiApplication.getUiApplication().pushScreen(new CrearUsuarioXmlScreen());
			}
			if (miObjectChoiceField.getSelectedIndex()==1)
			{
			 UiApplication.getUiApplication().pushScreen(new LeerUsuarioXmlScreen());
			}
			if (miObjectChoiceField.getSelectedIndex()==2)
			{
			 UiApplication.getUiApplication().pushScreen(new ActualizarUsuarioXmlScreen());
			}
			if (miObjectChoiceField.getSelectedIndex()==3)
			{
			 UiApplication.getUiApplication().pushScreen(new EliminarUsuarioXmlScreen());
			}
	    }
    }
}
